package com.qf.flash.mvp.presenter;

import com.qf.dblib.dao.impl.UserMgr;
import com.qf.flash.http.HttpManager;
import com.qf.flash.model.MyCollectShopBean;
import com.qf.flash.mvp.contract.MyCollectShopContract;
import com.qf.flash.utils.LogUtil;
import com.qf.flashlib.base.BasePresenter;
import com.qf.flashlib.base.BaseResponse;
import com.qf.flashlib.base.BaseSubscriber;
import com.qf.flashlib.util.RxUtils;

import java.util.List;

public class MyCollectShopPresenter extends BasePresenter<MyCollectShopContract.View> implements MyCollectShopContract.Presenter {
    private String uid = UserMgr.getInstance().getLoginUser().getUid();

    @Override
    public void getCollectShopList(String lo, String la, int page, int size) {
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .MY_COLLECT_SHOP_LIST(uid, lo, la, 1, 30)
                .compose(RxUtils.handleBaseResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<BaseResponse<List<MyCollectShopBean>>>(mRootView) {
                                   @Override
                                   public void onSuccess(BaseResponse<List<MyCollectShopBean>> listBaseResponse) {
                                       mRootView.setUi(listBaseResponse.getData(),listBaseResponse.getTotalPage());
                                   }

                                   @Override
                                   public void onError(Throwable t) {
                                       super.onError(t);
                                       mRootView.setUi(null,1);
                                   }
                               }
                ));
    }

    @Override
    public void deleteCollectShop(String shopIds) {
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .DELETE_COLLECT_SHOP(uid, shopIds)
                .compose(RxUtils.handleBaseResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<BaseResponse<Object>>(mRootView) {
                    @Override
                    public void onSuccess(BaseResponse<Object> response) {
                        LogUtil.d("删除收藏：response-- " + response.getMsg());
                        mRootView.deletedOver();
                    }
                })
        );
    }


}
